//
//  UIButton+Extension.swift
//  xinlangweibo
//
//  Created by yangshuo on 15/11/23.
//  Copyright © 2015年 yangshuo. All rights reserved.
//

import UIKit
//便利构造函数是不需要返回值的,构造函数执行完,对象就已经创建好
extension UIButton{
    convenience init(imageName: String, backImageName: String){
        //对象实例化
        self.init()
        
        //这个地方默认
        setImage(UIImage(named: imageName) , forState: UIControlState.Normal)
        setImage(UIImage(named: imageName + "_highlighted"), forState: UIControlState.Highlighted)
        setBackgroundImage(UIImage(named: backImageName), forState: UIControlState.Normal)
        setBackgroundImage(UIImage(named: backImageName + "_highlighted"), forState: UIControlState.Highlighted)
        //以后手动代码创建控件
        sizeToFit()
    }
    convenience init(title: String, color: UIColor, backImageName: String){//将变量抽取出来
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        setBackgroundImage(UIImage(named: backImageName), forState: .Normal)
        sizeToFit()
   }
    
    //底部视图按钮
    convenience init(title: String, color: UIColor, fontSize: CGFloat, imageName: String){//将变量抽取出来
        self.init()
        setTitle(title, forState: .Normal)
        setTitleColor(color, forState: .Normal)
        titleLabel?.font = UIFont.systemFontOfSize(fontSize)
        setImage(UIImage(named: imageName), forState: .Normal)
        sizeToFit()
    }

    
}

